import ajaxMainTableData from './ajaxMainTableData';
import updateButtonStatus from "./updateButtonStatus";
import handleAllpks from "./handleAllpks";


export default function getMainTableData() {
    const {
        searchModalValue,
        orgVal,
        queryOid,
        includeCheckedPsn,
        pageInfo
    } = this.state;


    let postData = {
        ...searchModalValue,
        pk_org: orgVal && orgVal.refpk,
        includeCheckedPsn,
        pageInfo: pageInfo
    };

    return ajaxMainTableData(postData)
        .then((res) => {
            if (res.success) {
                if (!res.data) {
                    res.data = {
                        'blacklist': {
                            rows: []
                        }
                    };
                }
                // res.data['blacklist'].rows.map((item) => {
                //     if (item.values['showorder'].value === '9999999') {
                //         item.values['showorder'].value = '';
                //     }
                // });
                const resPageInfo = res.data['blacklist'].pageInfo;
                let pks = res.data['blacklist'].allpks;
                if (resPageInfo) {
                    pks = pks.slice((resPageInfo.pageIndex - 1) * resPageInfo.pageSize, resPageInfo.pageIndex * resPageInfo.pageSize);
                }
                handleAllpks.set(pks);
                this.setState({
                    hasSearched: true,
                    pageInfo: res.data['blacklist'].pageInfo || {
                        pageSize: 10,
                        pageIndex: 1,
                        total: 0,
                        totalPage: 1
                    }
                }, () => {
                    updateButtonStatus.call(this);
                });
                this.props.editTable.setTableData('blacklist', {rows: res.data['blacklist'].rows});
            }
        });
}
